package com.weetop.aklyscan.activity;

import android.os.Bundle;
import android.view.View;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.base.BaseActivity;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.BaseList;
import com.weetop.aklyscan.bean.RecordBean;
import com.weetop.aklyscan.presenter.InventoryPresent;
import com.weetop.aklyscan.view.InventoryView;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class InventoryPeijianRecordDetail1Activity extends BaseActivity<InventoryPresent> implements InventoryView {
    String order_sn, time;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private CommonRecyclerAdapter<RecordBean> adapter;
    private List<RecordBean> list = new ArrayList<>();
    private int type;

    @Override
    protected InventoryPresent createPresenter() {
        return new InventoryPresent(this, this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inventory_peijian_record_detail1);
        ButterKnife.bind(this);
        order_sn = getIntent().getStringExtra("order_sn");
        time = getIntent().getStringExtra("time");
        type = getIntent().getIntExtra("type", InventoryRecordActivity1.TYPE_FACTORY_CHANPIN);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<RecordBean>(mActivity, R.layout.item_inventory_record, list) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, RecordBean item, int position) {
                if (type == InventoryRecordActivity1.TYPE_FACTORY_CHANPIN) {
                    helper.setText(R.id.tv_id, position + 1 + "");
                    helper.setText(R.id.sn, item.getSerial_code());
                    helper.setText(R.id.name, item.getGoods_name());
                    helper.setText(R.id.model, item.getGoods_model());
                    helper.setText(R.id.zzx, item.getTransit_code());
                    helper.setText(R.id.huojiahao, item.getWarehouse_coordinates());
                } else {
                    helper.setText(R.id.tv_id, position + 1 + "");
                    helper.setText(R.id.sn, item.getMatter_code());
                    helper.setText(R.id.name, item.getMatter_name());
                    helper.setText(R.id.model, item.getYp_time());
                    helper.setText(R.id.zzx, item.getTransit_code());
                    helper.setText(R.id.huojiahao, item.getWarehouse_coordinates());
                }
            }
        };
        recyclerView.setAdapter(adapter);
        if (type == InventoryRecordActivity1.TYPE_FACTORY_PEIJIAN) {
            mPresenter.Into74(time, order_sn);
        } else if (type == InventoryRecordActivity1.TYPE_FACTORY_PEIJIAN_PRODUCT) {
            mPresenter.Into68(time, order_sn);
        } else {
            mPresenter.Into51(time, order_sn);
        }
    }

    @Override
    public void getInto51Success(BaseModel<List<RecordBean>> o) {
        List<RecordBean> listBeans = o.getData();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(list);
    }

    @Override
    public void getInto74Success(BaseModel<BaseList<RecordBean>> o) {
        List<RecordBean> listBeans = o.getData().getList_data();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(list);
    }

    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
